package com.sgam.mf.domain.sys;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.commons.lang.StringUtils;

@Entity
@Table(name = "SYS_MAIN_MENU")
public class SysMainMenu implements Comparable<SysMainMenu> {

	@Id
	@Column(name = "ID")
	@GeneratedValue
	private Integer id;
	

	@Column(name = "PARENT_ID")
	private Integer parentId;	

	@Column(name = "VISUAL_ORDER")
	private Integer visualOrder;	

	@Column(name = "TAG_ID")
	private String tagId;

	@Column(name = "TAG_TEXT")
	private String tagText;

	@Column(name = "TAG_URL")
	private String tagUrl;

	@Column(name = "TAG_IMAGEURL")
	private String tagImageurl;
	
	@OneToMany(mappedBy="parentId", fetch= FetchType.EAGER)
	private List<SysMainMenu> items =  new ArrayList<SysMainMenu>(0);
	
	
	  public int compareTo(SysMainMenu compareObject)
	    {
	        if (getVisualOrder()< compareObject.getVisualOrder())
	            return -1;
	        else if (getVisualOrder() == compareObject.getVisualOrder())
	            return 0;
	        else
	            return 1;
	    }
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
	public Integer getParentId() {
		return parentId;
	}

	public void setParentId(Integer parentId) {
		this.parentId = parentId;
	}

	public Integer getVisualOrder() {
		return visualOrder;
	}

	public void setVisualOrder(Integer visualOrder) {
		this.visualOrder = visualOrder;
	}

	public String getTagId() {
		return tagId;
	}

	public void setTagId(String tagId) {
		this.tagId = tagId;
	}

	public String getTagText() {
		return tagText;
	}

	public void setTagText(String tagText) {
		this.tagText = tagText;
	}

	public String getTagUrl() {
		return tagUrl; 
	}

	public void setTagUrl(String tagUrl) {
		this.tagUrl = tagUrl;
	}

	public String getTagImageurl() {
		return tagImageurl;
	}

	public void setTagImageurl(String tagImageurl) {
		this.tagImageurl = tagImageurl;
	}

	public List<SysMainMenu> getItems() {
		return items;
	}

	public void setItems(List<SysMainMenu> items) {
		this.items = items;
	}


	public String toString(){
		String result = "id = " + 			this.id + "\n" +
						"parentId = " + 	this.parentId + "\n" +
						"visualOrder =" + 	this.visualOrder + "\n" +
						"tagId = "+ 		this.tagId + "\n" +
						"tagText = " + 		this.tagText + "\n" +
						"tagUrl = " + 		this.tagUrl + "\n" +
						"tagImageurl = " + 	this.tagImageurl;    
		return result;
	}
	
	public String toHTMLStringOpen(){
		String result = "<li>";
		String tagA_open = "<a id= '" + this.tagId + "' href= '" + this.tagUrl + "' >";
		String tagA_close = "</a>";
		
		String tagImg_open = "<IMG alt= '" + this.tagText + "' src='" + this.tagImageurl + "' />";
		
		if (StringUtils.isNotBlank(this.tagImageurl)  ) {
			result = result + tagA_open + tagImg_open + tagA_close;
		} else {
			result = result + tagA_open + this.tagText + tagA_close;
		}
		
		return result;
	}
	
	public String toHTMLStringClose(){
			
		return  "</li>";
	}	
	
	//<li><a id="btHome" 		href="home"><IMG alt="HOME" src="resources/images/home_icon16.png" width="22px" /></a></li>
	
	
}
